<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>

    let num1 = [2, 4, 7, 8, 10]
    let num2 = [1, 3, 9, 10, 20, 21, 30]
    function fn(num1, num2) {
        let i = 0;
        let j = 0
        let res = []
        while (i < num1.length && j < num2.length) {
            if (num1[i] < num2[j]) {
                res.push(num1[i])
                i++
            } else {
                res.push(num2[j])
                j++
            }
        }
        while (i < num1.length) {
            res.push(num1[i])
            i++
        }
        while (j < num2.length) {
            res.push(num2[j])
            j++
        }
        return res
    }
    console.log(fn(num1, num2));

</script>

</html>